package com.example.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.domain.SetmealDish;
import com.example.mapper.SetMealDishMapper;
import com.example.service.ISetmealDishService;
import com.example.service.ex.DeleteException;
import com.example.service.ex.InsertException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 套餐中的餐品业务
 */
@Service
public class SetmealDishServiceImpl implements ISetmealDishService {
    @Autowired
    private SetMealDishMapper setMealDishMapper;
    @Override
    public void save(List<SetmealDish> setmealDishes) {
        for (SetmealDish setmealDish :setmealDishes) {
            int insert = setMealDishMapper.insert(setmealDish);
            if (insert!=1){
                throw new InsertException("添加数据时产生未知的异常");
            }
        }

    }

    @Override
    public void remove(List<Long> ids) {
        LambdaQueryWrapper<SetmealDish> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(ids!=null,SetmealDish::getSetmealId,ids);
        //删除餐品
        int delete = setMealDishMapper.delete(lambdaQueryWrapper);
        if (delete<=0){
            throw new DeleteException("删除数据时出现未知的异常");
        }
    }
}
